<?php
/**
 * Class AgentArticle
 * Desc  代理文章Model
 * Create on 2021/8/26 14:58
 * Create by wangyafang
 */

namespace app\api\model\xyb;


use think\Db;

class AgentArticle extends Base
{
    protected $name = 'xyb_agent_article';

    protected $type = [
        'createtime'    =>  'timestamp:Y-m-d H:i:s',
    ];

    /*,$where,'id,name as title','weigh desc,id desc'*/
    public static function getAgentArticleList($agent_id, $users_identity){

        $lists = AgentArticle::field('id,name as title,createtime')->where(function ($query) use($agent_id){
            $query->whereRaw("FIND_IN_SET(1, agent_id)")->whereOrRaw("FIND_IN_SET({$agent_id}, agent_id)");
        })->where(function ($query) use($users_identity){
            $query->whereRaw("FIND_IN_SET(1, user_type)");
            $map = [1=> 2, 2=> 3, 3=> 4];
            if($users_identity == 4){
                $user_type = isset($map[$users_identity])?isset($map[$users_identity]):2;
                $query->whereOrRaw("FIND_IN_SET({$user_type}, user_type)");
            } else {
                $query->whereOrRaw("FIND_IN_SET(3, user_type)")->whereOrRaw("FIND_IN_SET(4, user_type)");
            }
        })->where('status', 'eq','normal')->order('id desc')->paginate(10);
        return $lists;
    }
}